@extends('layouts.buz.layout', ['header_active' => 'settle'])
@section('full-content')

    @include('layouts.buz.sidebar.remit', ['active' => 'withdraw'])

    <div class="yhy-member col-sm-9 col-sm-push-3 col-md-10 col-md-push-2 col-xs-12">
        @include('buz.remit.labatitle')
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    提现
                </h4>
            </div>
            <div class="panel-body">
                <form class="form-horizontal member" role="form" id="withdrawForm">
                    <div class="row">

                        <div class="col-sm-8">
                            <div class="form-group">
                                <label for="firstname" class="col-sm-3 control-label">提现卡号</label>
                                <div class="col-sm-8">
                                    {{hidePrivateData($bank->account, true)}} ({{$bankName}})
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="form-group">
                                <label for="firstname" class="col-sm-3 control-label">提现金额</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="money">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="form-group">
                                <label for="lastname" class="col-sm-3 textRight">验证码：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" name="sms_code">
                                </div>
                                <div class="col-sm-4">
                                    <button type="button" class="btn btn-info" id="withdrawSendCode">发送验证码</button>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="form-group">
                                <label for="firstname" class="col-sm-3 textRight">交易密码：</label>
                                <div class=" col-sm-5">
                                    <input type="password" class="form-control" name="trade_pwd">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-8">
                                <div class="form-group">
                                    <label for="firstname" class="col-sm-3 control-label"></label>
                                    <div class="col-sm-8">
                                        <button type="button" class="btn btn-primary" onclick="confirmWithdraw()">确定</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection()
@section('dialog')

@endsection()
@section('bottom_js')
    <script>
        $('#withdrawForm').bootstrapValidator({
            message: '这个值没有被验证',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                money: {
                    message: '提现金额不能为空',
                    validators: {
                        notEmpty: {
                            message: '提现金额不能为空'
                        }
                    }
                },
                trade_pwd: {
                    message: '交易密码不能为空',
                    validators: {
                        notEmpty: {
                            message: '交易密码不能为空'
                        }
                    }
                },
                sms_code: {
                    message: '短信验证码不能为空',
                    validators: {
                        notEmpty: {
                            message: '短信验证码不能为空'
                        }
                    }
                }
            }
        });
        //提现提交
        function confirmWithdraw(){
            var bootstrapValidator = $('#withdrawForm').data("bootstrapValidator");
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
                var data = $("#withdrawForm").serialize();
                console.log(data);
                $.ajax({
                    url: "/api/order/withdraw",
                    data: data,
                    type: 'post',
                    success:function(data){
                        console.log(data);
                        if(filterAjaxData(data)){
                            showMsg("提现成功");
                            window.location.reload();
//                        }else {
//                            showMsg(data.message);
                        }
                    }
                });
            }
        }
        $(function(){
            //发送短信验证码
            $("#withdrawSendCode").click(function(){
                var that = $(this);
                $.ajax({
                    url: "/api/tool/sms/remit",
                    data: {type: 4},
                    type: 'post',
                    success:function(data){
                        if(data.code == 0){
                            setTime(that);
                            showMsg("发送成功");
                        }else {
                            showMsg(data.message);
                        }
                    }
                });
            });
        });
    </script>
@endsection()
